import { login, sysProfile } from '@/api/user'
import { getToken, setToken } from '@/utils/auth'

const state = {
  token: getToken() || '',
  userInfo: ''
}
const mutations = {
  setToken(state, value) {
    state.token = value
    setToken(value)
  },
  setUserInfo(state, value) {
    state.userInfo = value
  },
  logout() {
    state.token = ''
    setToken('')
  }
}
const actions = {
  // 登陆调用
  async toLogin({ commit }, value) {
    console.log(1234)
    const res = await login(value)
    console.log('res', res)
    commit('setToken', res.data)
  },
  // 获取个人用户信息
  async getUserInfo({ commit }) {
    const res = await sysProfile()
    commit('setUserInfo', res.data)
  }
}
const getters = {}

export default {
  namespaced: true,
  state,
  mutations,
  actions,
  getters
}
